/**
 * JSON格式化
 * @param value
 */
export function formatJSON(value: string) {
  try {
    value = JSON.stringify(JSON.parse(value), null, 2);
  } catch (e) {
    value = '';
  }
  return value;
}

/**
 * JSON压缩
 * @param value
 */
export function compressJSON(value: string) {
  try {
    value = JSON.stringify(JSON.parse(value));
  } catch (e) {
    value = '';
  }
  return value;
}

/**
 * 判断是否为json字符串
 * @param str
 */
export function isJSON(str: string): boolean {
  try {
    JSON.parse(str);
    return true;
  } catch (e) {
    return false;
  }
}

/**
 * 获取url参数
 */
export function getUrlParams(): Record<string, string> {
  const params: Record<string, string> = {};
  const queryString = window.location.search.substring(1);
  const urlParams = new URLSearchParams(queryString);

  for (const [key, value] of urlParams.entries()) {
    params[key] = value;
  }

  return params;
}
